<?php

use yii\helpers\Html;
use yii\grid\GridView;

/* @var $this yii\web\View */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = '联系人管理';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="contactor-index">



    <p>
        <?= Html::a('创建联系人信息', ['create'], ['class' => 'btn btn-success']) ?>
        <?= Html::a('导出联系人', ['export'], ['class' => 'btn btn-success']) ?>

        <?php $form = \yii\bootstrap\ActiveForm::begin([
            'method' => 'GET',
            'action' => '/contactor/index',
        ]); ?>
<!--        <input name="text" name="keyword" value="" placeholder="联系人或电话" form="form-control"/>-->
        <?=Html::textInput('keyword');?>
        <?= Html::submitButton('搜索' , ['class' =>  'btn btn-success']) ?>
        <?php
            $form->end();
        ?>
    </p>
    <?=Yii::$app->session->getFlash('success');?>
    <?=Yii::$app->session->getFlash('error');?>

    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'columns' => [
            ['class' => 'yii\grid\SerialColumn'],

            'name',
            'company_name',
            'position',
            'mobile',
            // 'web_site',
            // 'wechat',
            // 'create_time:datetime',
            // 'update_time:datetime',
            // 'is_hot',

            [
                'class' => 'yii\grid\ActionColumn',
                'template' => '{view}&nbsp;&nbsp;&nbsp;&nbsp;{update}&nbsp;&nbsp;&nbsp;&nbsp;{delete}&nbsp;&nbsp;&nbsp;&nbsp;{item}',
                'buttons' => [
                    'item' => function($url, $model, $key){
                        if($model->is_hot == 0){
                            $url = \yii\helpers\Url::to(['/contactor/set-hot','cid' => $model->id]);
                            $options = [
                                'title' => '推荐',
                                'aria-label' => '推荐',
                            ];
                            $text = '推荐';
                        }else{
                            $url = \yii\helpers\Url::to(['/contactor/cancel-hot','cid' => $model->id]);
                            $options = [
                                'title' => '取消推荐',
                                'aria-label' => '取消推荐',
                            ];
                            $text = '取消推荐';
                        }

                        return Html::a($text,$url,$options);
                    }
                ],
            ],
        ],
    ]); ?>

</div>
